<template>
	<view>
		<view class="cell">
			<view class="label">交易所姓名</view>
			<input v-model="form.jy_name" maxlength="6" class="input" type="text" placeholder="请输入验证码" />
		</view>
		<view class="cell">
			<view class="label">交易所帐号</view>
			<input type="number" v-if="" maxlength="11" v-model="form.jy_account" class="input" placeholder="请输入交易所帐号" />
			
		</view>

	

		<!-- <view class="tips">需要先使用微信登录，在【我的】-【设置】中绑定手机号后，才能使用手机号登录</view> -->

		<view class="fixed-wrap" v-if="!userinfo.jy_account">
			<button @click="login()" :disabled="loginDisabled"  :style="codeDisabled?'':'background: #333;color: #fff;'"  class="btn-login">确定</button>
		</view>
	</view>
</template>

<script>
	import { isMobile } from '@/utils/validator.js';

	const SECONDS = 60;

	export default {
		data() {
			return {
				form: {
					jy_account: '',
					jy_name: ''
				},
				userinfo:null,	

			};
		},
		onShow() {
			this.get_info()
		},
		onLoad() {
			if(uni.getStorageSync('inviteCode')) {
				this.invite_code = uni.getStorageSync('inviteCode');
			}
		},
		computed: {
			loginDisabled() {
				return !(this.form.jy_name && this.form.jy_account);
			},
			codeDisabled() {
				return !(this.form.jy_name && !this.form.jy_account);
			}
		},
		methods: {
			get_info(){
				uni.showLoading({ title: '正在加载', mask: true });
				var _this = this;
				_this.$api.request('/api/user/get_info', {page:this.page}, uni.getStorageSync('token'), function(res) {
					uni.hideLoading();
					if (res.code == 1) {
						_this.userinfo = res.data;
						_this.form.jy_account = res.data.jy_account
						_this.form.jy_name = res.data.jy_name
					}
					uni.hideLoading();
				});
			},
			// 登录
			loginHandle() {
			
			},

			// 获取验证码
			getCode() {
				if (!isMobile(this.form.mobile)) {
					return uni.showToast({
						title: '手机号码有误',
						icon: 'none'
					});
				}
				this.countdown();
			},

			// 倒计时
			countdown() {
				this.counting = true;
				this.codeText = this.seconds + ' s';
				this.timer = setInterval(() => {
					if (this.seconds > 0) {
						this.seconds--;
						this.codeText = this.seconds + ' s';
					} else {
						this.counting = false;
						this.codeText = '再次获取';
						this.seconds = SECONDS;
						clearInterval(this.timer);
						this.timer = null;
					}
				}, 1000);
			},
			login() {
			
				
				console.log(777777777)
				
				var _this = this;
			
					this.$api.request('/api/user/mobilelogin_jiaoyi', this.form, '', function(res){
						console.log(res);
						if(res.code == 1) {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
							_this.get_info();
						}else{
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					});
				
			}
		}
	};
</script>

<style lang="less">
	.cell {
		display: flex;
		align-items: center;
		padding: 16rpx 32rpx;
		border-bottom: 1px solid #f3f3f3;

		.label {
			font-size: 32rpx;
			font-weight: 600;
		}

		.input {
			flex: 1;
			height: 100rpx;
			padding: 0 32rpx;
		}

		.btn-code {
			font-size: 28rpx;
			background: #333;
			color: #fff;
			width: 200rpx;
		}

		.input-placeholder {
			color: #ccc;
		}
	}

	.tips {
		font-size: 26rpx;
		color: #999;
		padding: 64rpx 32rpx;
	}

	.fixed-wrap {
		position: fixed;
		left: 48rpx;
		right: 48rpx;
		bottom: 100rpx;
		.btn-login {
			background: #333;
			color: #fff;
			font-weight: bold;
			height: 100rpx;
			line-height: 100rpx;
		}
	}
	button .btn-login{
		background: red;
	}
	button[disabled].btn-login {
		background: #e6e6e6;
	}

	button[disabled].btn-code {
		background: #e6e6e6;
	}


		
	button::after {
		border: none;
	}
</style>
